package com.lfg.leetcode.leetcode0;

public class No66plusOne {

    public static void main(String[] args) {
        ;
        int[] ret = plusOne(new int[]{9});
        System.out.println(ret);
    }

    public static int[] plusOne(int[] digits) {
        if (digits.length == 0) {
            return digits;
        }
        int tmp = 1;
        for (int i = digits.length - 1; i >= 0 && tmp != 0; i--) {
            tmp += digits[i];
            digits[i] = tmp % 10;
            tmp = tmp / 10;
        }
        if (tmp > 0) {
            int[] ret = new int[digits.length + 1];
            ret[0] = tmp;
            System.arraycopy(digits, 0, ret, 1, digits.length);
            return ret;
        }
        return digits;
    }
}

